package li.controller;

import li.dto.TbUser;
import li.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    UserService us;

    @RequestMapping("/login")
    public String login(String account, String password, HttpSession session){
        System.out.println("帐号："+account+",密码："+password);
        TbUser user = us.doLogin(account,password);
        if(user==null){
            return null;
        }
        session.setAttribute("user",user);
        return user.getAccount();
    }
    @RequestMapping("/regist")
    public String regist(TbUser user){

        us.regist(user);
        return "注册成功";
    }

}
